package com.example.zqm.git72.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zqm.git72.JavaBean.ClubMap;
import com.example.zqm.git72.JavaBean.Master;
import com.example.zqm.git72.R;
import com.squareup.picasso.Picasso;

import java.util.List;

//import com.example.zqm.git72.Activity.FoodActivity;

/**
 * Created by Administrator on 2017/3/6 0006.
 */

public class MasterVideoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
   // private List<Master> mDataList;
    private LayoutInflater mLayoutInflater;
    private Master master;
    private List<Master.MvideoEntity> mDataList;
    //构造方法
    public MasterVideoListAdapter(Context mContext, List<Master.MvideoEntity> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
//        if (mDataList.size() >0){
//           master = mDataList.get(0);
//        }
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_mastervideo,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //把viewhoder数据映射到
        Master.MvideoEntity entity = mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        //viewHolder.mvideo_name.setText("视频名："+master.getMvideo().get(position).getMvideo_name());
        viewHolder.mvideo_name.setText("视频名："+entity.getMvideo_name());
        //viewHolder.hits.setText("点击量:"+master.getMvideo().get(position).getHits());
        viewHolder.hits.setText("点击量:"+entity.getHits());
        if(entity.getThumb().equals("")){
            Picasso.with(mContext).load("https://b-ssl.duitang.com/uploads/item/201409/03/20140903102455_SNNnA.png"
            )
                    .resize(50,50).into(viewHolder.mvideo_thumb);
        }else{
            String picUrl = "http://172.24.10.175/workout/Uploads/" + entity.getThumb();

            Picasso.with(mContext).load(picUrl.toString())
                    .resize(50,50).into(viewHolder.mvideo_thumb);
        }
        //Context上下文在很多Android Api中都是必须的,图片网络加载地址,想进行图片展示的ImageView
//        if (master.getMvideo().size() > 0){
//
//
//
//        }

    }

    @Override
    public int getItemCount() {
        //return master.getMvideo().size();
        return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView mvideo_thumb;
        TextView mvideo_name,hits;

        //构造方法
        public ViewHolder(View itemView) {
            super(itemView);
            mvideo_name = (TextView) itemView.findViewById(R.id.mvideo_name);
            mvideo_thumb = (ImageView) itemView.findViewById(R.id.mvideo_thumb);
            hits=(TextView) itemView.findViewById(R.id.hits);


        }
    }

}
